package com.alan.designMode.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 动态代理Handler类
 * Created by Alan on 17-8-29
 */
public class MyInvocationHandler implements InvocationHandler{

    //被代理的实例
    Object target = null;

    public MyInvocationHandler(Object _obj){
        this.target = _obj;
    }

    //调用被代理的方法
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //执行被代理的方法
        System.out.println("before");
        Object obj = method.invoke(this.target,args);
        System.out.println("after");
        return obj;
    }

}
